#include "jimeise.h"
#include "bjglobal.h"
#include "downloadweb.h"
#include "usrdef.h"
#include <vector>
using namespace std;

struct STRU_INDEX_INFO
{
	int num;
	string url;
	STRU_INDEX_INFO(){clear();};
	void clear()
	{
		num = 0;
		url.clear();
	};
};

int get_index(vector<STRU_INDEX_INFO>& vIndexInfo)
{
	IQuery q(BJGlobal::dbconn, true);
	q << "select url, num from index_table where status != 0 ";
	q.exec();
	STRU_INDEX_INFO stru_index_info;
	while (!q.eof())
	{
		stru_index_info.clear();
		q >> stru_index_info.url >> stru_index_info.num;
		vIndexInfo.push_back(stru_index_info);
	}
	if (vIndexInfo.empty())
	{
		stru_index_info.num = 1;
		stru_index_info.url = "http://www.jimeise.net/";
		vIndexInfo.push_back(stru_index_info);
	}

	return 0;

}

int jimeise_parse_index()
{
	vector<STRU_INDEX_INFO> vIndexInfo;
	DownloadWeb dw;
	string strHtml;
	
	for (size_t i = 0; i < vIndexInfo.size(); ++i)
	{
		STRU_INDEX_INFO stru_index_info = vIndexInfo[i];
		if (dw.getHttp(stru_index_info.url,strHtml) != 0)
		{
			DBGPRINTF("download failed, will sleep 3 seconds before try next");
			sleep(3);
			continue;
		}

		
	}
	
		
	return 0;
}



